package com.fund.utils;


import com.fund.enums.ResponseCodeEnume;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
 * 应用统一返回结果数据封装类
 *
 * @param <T> 返回结果数据类型
 * @author Administrator
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class AppResponse<T> {

    private Integer code;
    private String msg;
    private T data;


    public AppResponse(Integer code, String message) {
        this.code = code;
        this.msg = message;
    }

    /**
     * 快速响应成功
     *
     * @param data
     * @return
     */
    public static <T> AppResponse<T> ok(T data) {
        AppResponse<T> resp = new AppResponse<T>();
        resp.setCode(ResponseCodeEnume.SUCCESS.getCode());
        resp.setMsg(ResponseCodeEnume.SUCCESS.getMsg());
        resp.setData(data);
        return resp;
    }
    public static <T> AppResponse<T> ok(String msg,T data) {
        AppResponse<T> resp = new AppResponse<T>();
        resp.setCode(ResponseCodeEnume.SUCCESS.getCode());
        resp.setMsg(msg);
        resp.setData(data);
        return resp;
    }

    /**
     * 快速响应失败
     */
    public static <T> AppResponse<T> fail(T data) {
        AppResponse<T> resp = new AppResponse<T>();
        resp.setCode(ResponseCodeEnume.FAIL.getCode());
        resp.setMsg(ResponseCodeEnume.FAIL.getMsg());
        resp.setData(data);
        return resp;
    }

}
